package com.crr.mall.ware.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import cn.hutool.core.bean.BeanUtil;
import com.crr.mall.common.bean.ResultBean;
import com.crr.mall.common.to.StockVO;
import com.crr.mall.common.utils.BaseController;
import com.crr.mall.ware.query.WareSkuQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.crr.mall.ware.entity.WareSkuEntity;
import com.crr.mall.ware.service.WareSkuService;
import com.crr.mall.common.utils.PageUtils;
import com.crr.mall.common.utils.R;



/**
 * 商品库存
 *
 * @author chenrenren
 * @email chenrenren@gmail.com
 * @date 2024-11-22 20:37:24
 */
@RestController
@RequestMapping("ware/waresku")
public class WareSkuController extends BaseController {
    @Autowired
    private WareSkuService wareSkuService;
//    @PostMapping("/ware/waresku/hasstock")
//    List<StockVO> getStock(@RequestBody List<Long> skuIds);
    @PostMapping("/hasstock")
    public List<StockVO> getStock(@RequestBody List<Long> skuIds){
        //只需要查询两个属性skuID stock
      List<StockVO> list= wareSkuService.queryStock(skuIds);
      return list;
    }

    @PostMapping ("/listinfo")
    // @RequiresPermissions("ware:waresku:list")
    public ResultBean skulist(@RequestBody WareSkuQuery wareSkuQuery){
        PageUtils page = wareSkuService.queryByCondition(BeanUtil.beanToMap(wareSkuQuery));

        return success("waresku列表",page);
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
   // @RequiresPermissions("ware:waresku:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = wareSkuService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
   // @RequiresPermissions("ware:waresku:info")
    public R info(@PathVariable("id") Long id){
		WareSkuEntity wareSku = wareSkuService.getById(id);

        return R.ok().put("wareSku", wareSku);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
   // @RequiresPermissions("ware:waresku:save")
    public R save(@RequestBody WareSkuEntity wareSku){
		wareSkuService.save(wareSku);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
   // @RequiresPermissions("ware:waresku:update")
    public R update(@RequestBody WareSkuEntity wareSku){
		wareSkuService.updateById(wareSku);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
   // @RequiresPermissions("ware:waresku:delete")
    public R delete(@RequestBody Long[] ids){
		wareSkuService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
